package com.systemic.controller;

import com.systemic.core.ResponseResult;
import com.systemic.pojo.Comment;
import com.systemic.service.CommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: CommentController
 * @Description: 评论控制层
 * @Author:
 * @CreateTime: 2024-01-20 16:36
 * @Version:
 **/
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    /**
     * 评论
     * @param comment
     * @return
     */
    @PostMapping("/create")
    public ResponseResult<String> create(@RequestBody Comment comment){
        int row = commentService.create(comment);
        return row!=0 ? ResponseResult.success("评论成功") : ResponseResult.failed("评论失败");
    }

    /**
     * 回复
     * @param comment
     * @return
     */
    @PostMapping("/reply")
    public ResponseResult<String> reply(@RequestBody Comment comment){
        int row = commentService.reply(comment);
        return row!=0 ? ResponseResult.success("回复成功") : ResponseResult.failed("回复失败");
    }


    /**
     * 评论区视图
     * @param did
     * @return
     */
    @GetMapping("/view/{did}")
    public ResponseResult<List<Comment>> getView(@PathVariable("did") Integer did){
        List<Comment> commentList = commentService.getView(did);
        return ResponseResult.success(commentList);
    }


    /**
     * 删除评论
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ResponseResult<String> delete(@PathVariable("id") Integer id){
        int row = commentService.delete(id);
        return row != 0 ? ResponseResult.success("删除成功") : ResponseResult.failed("删除失败");
    }

    /**
     * 批量删除评论
     * @param ids
     * @return
     */
    @GetMapping("/deleteList/{ids}")
    public ResponseResult<String> deleteList(@PathVariable("ids") Integer[] ids){
        int row = commentService.deleteList(ids);
        return row != 0 ? ResponseResult.success("删除成功！") : ResponseResult.failed("删除失败");
    }


}
